/**
 *	@file	telseq_takenori.c
 *	@brief	タケノリ　会話データ抽選＆再生
 *	@author	Miyuki Iwasawa
 *	@date	09.02.06
 */

#include "common.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/buflen.h"
#include "system/pm_rtc.h"
#include "gflib/touchpanel.h"
#include "field/eventflag.h"
#include "field/evwkdef.h"
#include "fielddata/script/saveflag.h"
#include "itemtool/itemsym.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_pg_tel.h"

#include "../pm_tel.h"
#include "tel/pmtel_def.h"
#include "tel/pmtel_datman.h"
#include "tel/pmtel_dat_def.h"
#include "../pmtel_seq.h"
#include "telseq_play.h"

/**
 *	@brief	電話　タケノリの会話抽選
 */
u16 PMTelPlayL_Takenori(PMTEL_DATA_MAN* man,PMTEL_TALK_WORK* wk)
{
	u8 time_zone5,takenori_flag = FALSE;
	wk->seq_code = TEL_SEQ_SIMPLE;

	//着信なし
	//同一マップにいるか？
	if(wk->pbk->map_id == man->zone_id)	{
		return TEL_TK_TAKENORI_NE;
	}
	//ノーマル発信
	wk->tmp_u8 = PMTelSv_GetTakenoriCounter(man->tel_sv);

	if(wk->tmp_u8 > 1){
		return TEL_TK_TAKENORI_EV01;
	}else if(wk->tmp_u8 == 1){
		return TEL_TK_TAKENORI_EV02;
	}
	//タケノリカウンターが0

	//タケノリフラグが既にOn?
	takenori_flag = PMTelSv_TakenoriFlagGet(man->tel_sv);
	if(takenori_flag && (!PMTelSv_RevengeFlagGet(man->tel_sv,PMTEL_NUMBER_TR_TAKENORI))){	//既に対戦終わってる
		return TEL_TK_TAKENORI_EV01;	//修行は続いているぞ……
	}

	time_zone5 = GF_RTC_ConvertHourToTimeZone(wk->rtc_time.hour);	//5段階のタイムゾーンを取得
	if(time_zone5 == TIMEZONE_EVENING || time_zone5 == TIMEZONE_NIGHT){
		return TEL_TK_TAKENORI_EV05;	//もう夜になっちゃった
	}
	//再戦フラグ他セット
	if(!takenori_flag){
		PMTelSv_TakenoriFlagSet(man->tel_sv,TRUE);
		PMTelSv_RevengeFlagSet(man->tel_sv,PMTEL_NUMBER_TR_TAKENORI,TRUE);
//		PMTelSv_ItemEvDataSet(man->tel_sv,PMTEL_NUMBER_TR_TAKENORI,wk->pbk->item);
	}

	if(wk->time_zone == TIMEZONE_GS_NOON){
		return TEL_TK_TAKENORI_EV04;
	}
	return TEL_TK_TAKENORI_EV03;
}
